﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SqlMiM.Common.ViewModel;
using System.Diagnostics;

namespace SqlMiM.Common.View
{
    /// <summary>
    /// Interaction logic for ServerLoginView.xaml
    /// </summary>
    public partial class ServerLoginView : UserControl
    {

        private Window owner;
        /// <summary>
        /// Current ServerLoginViewModel
        /// </summary>
        public ServerLoginViewModel ServerLoginViewModel
        {
            get;
            private set;
        }

        public Window Owner
        {
            get
            {
                if (owner == null)
                    owner = Window.GetWindow(this);

                return owner;
            }
        }

        public ServerLoginView()
        {
            InitializeComponent();

            this.ServerLoginViewModel = new ServerLoginViewModel();
            this.DataContext = this.ServerLoginViewModel;

            // Need to Set DialogResult to true on my parent, if Validation is correct
            this.ServerLoginViewModel.Validated += (sender, args) =>
            {
                try
                {
                    this.Owner.DialogResult = true;
                }
                catch 
                {
                    //
                }
            };
            
            // Add message to Dispatcher to set Focus on Combobox whenever it's possible
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                FocusManager.SetFocusedElement(this, cbx);
            }), System.Windows.Threading.DispatcherPriority.Input);
        

        }

       

        private void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
        }
       
    }
}
